package com.jerry.base.thread;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * User: Jerry
 * Date: 2024/1/31
 * Time: 20:35
 * Description:
 */
@Slf4j
public class ThreadUsage {

    static class Cat extends Thread {

        private int times = 0;

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                log.info("线程{} => 喵了{}次", Thread.currentThread().getName(), ++times);

                if (times ==10 ) {
                    break;
                }
            }
        }
    }

    public static void main(String[] args) {
        Cat cat = new Cat();
        cat.start();

        for (int i = 1; i <= 10; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.info("线程{} => 执行了{}次", Thread.currentThread().getName(), i);
        }
    }

}
